<?php
/**
 * Created by PhpStorm.
 * User: Mr.Li<LHB2002@qq.com>
 * Date: 2017-09-28
 * Time: 11:05
 */

namespace Resolution;


class Style
{
    private $style_name;
    private $width;
    private $height;
    private $quality;
    private $ignore;
    private $resolution = false;

    private $screen = array(
        'width'=>320,
        'height'=>480,
    );

    private $source = array(
        'width'=>'',
        'height'=>'',
    );

    //todo 响应模式时，根据屏幕尺寸计算应得的宽度
    function __set($name, $value)
    {
            $this->$name = $value;
    }

    function __get($name)
    {
        if(isset($this->$name)){
            if(in_array($name,array('width','height'))){
                $this->structure($name);
            }

            return $this->$name;

        }
        else{
            return null;
        }
    }

    /**
     * 重新构建尺寸
     * @param $name
     * @author Mr.Li<lhb2002@qq.com>
     */
    private function structure(){

        if( $this->source['width'] < $this->source['height'] ){
            $this->width = ($this->height/$this->source['height']) * $this->source['width'];
        }
        else{
            $this->height = ($this->width / $this->source['width'])*$this->source['height'];
        }
    }

    /**
     * 设置屏幕尺寸信息
     * @param $width
     * @param $height
     * @author Mr.Li<lhb2002@qq.com>
     */
    public function setScreen($width , $height ){
        $this->screen['width'] = $width;
        $this->screen['height'] = $height;

        if($this->resolution){
            $this->width = $width * $this->width;
            $this->height = $height * $this->height;
        }
    }

    /**
     * 获取屏幕尺寸信息
     * @param string $mode
     * @return array|mixed
     * @author Mr.Li<lhb2002@qq.com>
     */
    public function getScreen($mode=''){
        if(in_array($mode,array('width','height'))){
            return $this->screen[$mode];
        }
        else{
            return $this->screen;
        }
    }

    /**
     * 设置原图的尺寸，已用于计算尺寸
     * @param $width
     * @param $height
     * @author Mr.Li<lhb2002@qq.com>
     */
    public function setSource($width , $height){
        $this->source['width'] = $width;
        $this->source['height'] = $height;
    }

    //todo 获取缓存路径，响应式时，需要缓存不同尺寸的信息


}